<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px; width: 100%"
  >
    <el-col :span="20">
      <span>{{ nodeData.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex">
        <!-- 两个内容 -->
        <el-col :span="12">{{ nodeData.manager }}</el-col>
        <el-col :span="12">
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommond">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!root" command="edit"
                >编辑部门</el-dropdown-item
              >
              <el-dropdown-item v-if="!root" command="del"
                >删除部门</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { reqDelDepartments } from "@/api/departments";
export default {
  props: {
    nodeData: {
      type: Object,
      required: true,
    },
    root: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    handleCommond(type) {
      //   console.log("我被电击了", type);
      if (type === "add") {
        console.log("将来走添加代码");
        // 显示对话框
        this.$emit('add-depts',this.nodeData)
      }
      if (type === "edit") {
        console.log("将来走编辑代码");
        this.$emit('editDepts',this.nodeData)
      }
      if (type === "del") {
        console.log("将来走删除代码");
        console.log(this.nodeData);
        this.$confirm("此操作将会永久删除部门信息,是否继续?", "温馨提示")
          .then(async () => {
            const res = await reqDelDepartments(this.nodeData.id);
            console.log(res);
            this.$message.success("删除部门成功");
            this.$emit("del-depts");
          })
          .catch(() => {
            console.log("取消了");
          });
      }
    },
  },
};
</script>

<style>
</style>